import { call, put, takeEvery } from 'redux-saga/effects'
import { get } from 'utils/http'


function* loadDetailData (action) {
  let result = yield call(get, { 
  url: `/v1/thread/${action.paylod}`,
  headers: {
    'X-Request-Id':'4syolClakbUytmLtH2KJ39iITBgWl0iXpOG0tzfxUnwew2lrJkOIYgBXWa66ZziYOh3JgFWUE6yydbNg4y2Mog==',
    'X-Running-Env':'Q3OVXEArMgZNlMHtAxpu7ONj6bFtJQXn/rvs04BOX697Tr585tFrKIfZg2KoeUpgvnQYU5SNJ6oll+TA3FcxhCSpa6SvJgmuq4xYqBNA20NJ8ldwleqG5XO+/pJxDWDxaNNMPz7ogAvZMCU05jjILfwfb4xVDID+l4bJCv3PvZscJDIQEUoUSJwLTyrr7tv+gqSf9UY9s9WYRpJ1JOgOJVE/R7GAEfmgKwxF17NRO5ggEi+HSU8VLk4VqV/x4hOj'
  }})
  // console.log(result)
  yield put({
    type: 'LOAD_DETAIL_DATA',
    all: result.data
  })
}



function* loadCommonData (action) {
  let common = yield call(get, { 
  url: `/v1/thread/${action.paylod}/posts`,
  params:{
    page:'1'
  },
  headers: {
    'X-Request-Id':'dgmxgkvRVZg+WaDX0YdMU6N6CO/H3U7PGly02rBHH2aLDbd4W1BbasGWwtzi9qfI0xhQyL9Qx1Bli4ZNUSyBqg==',
    'X-Running-Env':'Q3OVXEArMgZNlMHtAxpu7ONj6bFtJQXn/rvs04BOX697Tr585tFrKIfZg2KoeUpgvnQYU5SNJ6oll+TA3FcxhCSpa6SvJgmuq4xYqBNA20NJ8ldwleqG5XO+/pJxDWDxaNNMPz7ogAvZMCU05jjILfwfb4xVDID+l4bJCv3PvZscJDIQEUoUSJwLTyrr7tv+gqSf9UY9s9WYRpJ1JOgOJVE/R7GAEfmgKwxF17NRO5ggEi+HSU8VLk4VqV/x4hOj'
}})
// console.log(common);
  yield put({
    type: 'LOAD_COMMON_DATA',
    common: common.data
  })
}

function* sagas () {
  yield takeEvery('SAGA_LOAD_DETAIL_DATA', loadDetailData)
  yield takeEvery('SAGA_LOAD_COMMON_DATA', loadCommonData)
}

export default sagas